package com.rd.student.ruanjian.class3.gaochenxi.NumberSeven;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class NumberSeven {

      public static void main(String[] args) {
            String[] strings1={"哈尔滨","大庆","绥化","齐齐哈尔","杭州","宁波","南昌","广州","福州","厦门"};
            String[] strings2={"黑龙江省","黑龙江省","黑龙江省","黑龙江省","浙江省","浙江省","江西省","广东省","福建省","福建省"};

            System.out.println("显示各个身份的城市数量：");
            HashMap hashMap = FilterFunc(strings2,1);
            returnHash(hashMap);
            System.out.println("显示: 省份--城市拼接字符串");
            String s = returnString(strings2, strings1);
            System.out.println(s);

      }
      

      //为了显示各个身份城市的个数
      public static HashMap FilterFunc(String []str1,int type) {
            HashMap hashMap = new HashMap();
            String str2 = "";
            for (int i = 0; i < str1.length; i++) {
                  switch (type){
                        case 1:
                              str2=str1[i];
                              break;
                  }
                  if (hashMap.containsKey(str2)==false){
                        hashMap.put(str2,1);
                  }else{
                        int value= (int) hashMap.get(str2);
                        hashMap.put(str2,value+1);
                  }
            }
            return hashMap;
      }
      
      //拼接各个省份和城市的字符串
      public static String returnString(String[] string1,String[] string2){
            String str="";
            for(int i=0;i<string1.length;i++) {
                  str=str.concat("{"+string1[i]+"="+string2[i]+"}");
            }
            return str;
      }

      public static void returnHash(HashMap hashMap){
            Set set=hashMap.keySet();
            Iterator it=set.iterator();
            while(it.hasNext()){
                  Object key=it.next();
                  Object value=hashMap.get(key);
                  System.out.println("<"+key+"  "+value+"个"+">");
            }
      }
}
